package com.sevenit.nj.yrmtfish.common;

import java.util.LinkedList;
import java.util.List;

import android.app.Activity;
import android.app.Application;

public class AppManager extends Application {

	private static List<Activity> activityList = new LinkedList<Activity>();

	/**
     * 添加Activity到容器中
     * @param activity
     */
    public static void addActivity(Activity activity) {
    	activityList.add(activity);
    }
    
    /**
     * 遍历所有Activity,finish给定的Activity
     * @param strActivityName
     */
    public static void closePage(String activityName) {
    	for(int i = 0; i < activityList.size(); i++){
    		Activity activity = activityList.get(i);
    		if(activity.getClass().getName().equals(activityName)){
    			activity.finish();
    			activityList.remove(i);
    			i--;
    		}
    	}
    }
    
    /**
     * 遍历所有Activity，回到主菜单，并finish其他Activity
     */
    public static void goMenu() {
    	for(int i=0;i<activityList.size();i++){
    		Activity activity = activityList.get(i);
    		String strClassName = activity.getClass().getSimpleName();
    		if(!"MainMenu".equals(strClassName)){
    			activity.finish();
    			activityList.remove(i);
    			i--;
    		}
    	}
    }
    
    /**
     * 返回所有Activity的数量.
     */
    public static int getActCount() {
    	return activityList.size();
    }
    
    /**
     * 获取最顶层的Activity
     */
    public static Activity getTopActivity() {
    	
    	return activityList.get(activityList.size() - 1);
    }
    
    /**
     * 遍历所有Activity并finish
     */
    public static void sysExit() {
    	for(Activity activity:activityList) {
    		activity.finish();
    	}
    	System.exit(0);
    }
}
